class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        long long right=0;long long left =0;long long n=nums.size()-1;
        long long sum=0;long long ret=1e15;
        while(right<=n)
        {
            sum+=nums[right];
            while(sum>=target)//滑动窗口虽然都是两层循环，但是时间复杂度其实是O(n)
            {
                ret=min(ret,right-left+1);
                sum-=nums[left];left++;//注意是先减小和再加加
            }
            right++;
        }
        if(ret==1e15) return 0;
        else return ret;
    }
};